package com.migration.model.migration.scripts;

import com.migration.model.migration.AbstractMigrationScript;

/**
 * 风险评估-设备表(risk_device_chemical)迁移脚本
 */
public class A005_RiskDeviceMigrationScript extends AbstractMigrationScript {

    /**
     * 构造函数，初始化迁移配置
     */
    public A005_RiskDeviceMigrationScript() {
        super(
            "risk_device",
            "风险评估-设备数据迁移",
            "ra_node",
            "risk_device",
            5
        );
    }

    /**
     * 生成迁移数据的SQL
     *
     * @return 迁移数据的SQL
     */
    @Override
    protected String generateMigrationSql() {
        return "INSERT INTO risk_device (\n" +
               "  id,\n" +
               "  tenant_id,\n" +
               "  department_id,\n" +
               "  device_group_id,\n" +
               "  device_name,\n" +
               "  device_type_id,\n" +
               "  device_color,\n" +
               "  device_description,\n" +
               "  device_tag_number,\n" +
               "  main_parameters,\n" +
               "  schedule_date,\n" +
               "  accident_chains_num,\n" +
               "  sort_num,\n" +
               "  create_time,\n" +
               "  update_time,\n" +
               "  create_by,\n" +
               "  update_by,\n" +
               "  is_del\n" +
               ")\n" +
               "SELECT\n" +
               "  n.id,\n" +
               "  1 as tenant_id,\n" +
               "  n.tenant_id as department_id,\n" +
               "  ng.group_id,\n" +
               "  n.node_name,\n" +
               "  ne.equip_id,\n" +
               "  n.color,\n" +
               "  n.node_desc,\n" +
               "  n.bit_no,\n" +
               "  n.major_param,\n" +
               "  DATE_FORMAT(n.valid_date, '%Y-%m-%d'),\n" +
               "  0,\n" +
               "  n.sort_no,\n" +
               "  DATE_FORMAT(n.create_time, '%Y-%m-%d %H:%i:%s'),\n" +
               "  DATE_FORMAT(n.update_time, '%Y-%m-%d %H:%i:%s'),\n" +
               "  1,\n" +
               "  1,\n" +
               "  n.is_del\n" +
               "FROM\n" +
               "  risk_lunnan_test.ra_node n\n" +
               "LEFT JOIN risk_lunnan_test.ra_node_group ng ON ng.node_id = n.id\n" +
               "LEFT JOIN risk_lunnan_test.ra_node_equip ne ON ne.node_id = n.id;";
    }

    /**
     * 获取源数据SQL
     *
     * @return 源数据查询SQL
     */
    public String getSourceSql() {
        return "SELECT\n" +
               "  n.id,\n" +
               "  n.tenant_id,\n" +
               "  ng.group_id,\n" +
               "  n.node_name,\n" +
               "  ne.equip_id,\n" +
               "  n.color,\n" +
               "  n.node_desc,\n" +
               "  n.bit_no,\n" +
               "  n.major_param,\n" +
               "  n.valid_date,\n" +
               "  n.sort_no,\n" +
               "  n.create_time,\n" +
               "  n.update_time,\n" +
               "  n.is_del\n" +
               "FROM\n" +
               "  risk_lunnan_test.ra_node n\n" +
               "LEFT JOIN risk_lunnan_test.ra_node_group ng ON ng.node_id = n.id\n" +
               "LEFT JOIN risk_lunnan_test.ra_node_equip ne ON ne.node_id = n.id;";
    }

    /**
     * 获取目标数据SQL模板
     *
     * @return 目标数据SQL模板
     */
    public String getTargetSqlTemplate() {
        return "INSERT INTO risk_device (\n" +
               "  id,\n" +
               "  tenant_id,\n" +
               "  department_id,\n" +
               "  device_group_id,\n" +
               "  device_name,\n" +
               "  device_type_id,\n" +
               "  device_color,\n" +
               "  device_description,\n" +
               "  device_tag_number,\n" +
               "  main_parameters,\n" +
               "  schedule_date,\n" +
               "  accident_chains_num,\n" +
               "  sort_num,\n" +
               "  create_time,\n" +
               "  update_time,\n" +
               "  create_by,\n" +
               "  update_by,\n" +
               "  is_del\n" +
               ")";
    }
}
